{extend name="/layouts/base" /}

{block name="title"}管理评论 - {$CONFIG->SITE->title}{/block}

{block name="content"}
<div id="manage-comments" class="container-xxl">
    
    <div class="row mt-md-4 mt-2">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    
                    <div class="dropdown float-end">
                        <a href="javascript:;" class="dropdown-toggle arrow-none card-drop" data-bs-toggle="dropdown" aria-expanded="false">
                            <i class="mdi mdi-dots-vertical"></i>
                        </a>
                        <div class="dropdown-menu dropdown-menu-end">
                            <a v-on:click="initData('','',true)" href="javascript:;" class="dropdown-item">
                                <i class="mdi mdi-autorenew me-1"></i>刷新
                            </a>
                            <a v-on:click="deleteComments()" href="javascript:;" class="dropdown-item">
                                <i class="mdi mdi mdi-delete-outline me-1"></i>批量删除
                            </a>
                        </div>
                    </div>
                    
                    <div class="row pb-2">
                        <div class="com-md-6">
                            <div class="card-body pt-0 pb-0">
                                <div class="app-search d-block">
                                    <div class="input-group">
                                        <input v-model="search_value" v-on:keyup.enter.native="initData('','',true)" type="text" class="form-control mw-250" placeholder="用户名 | 邮箱 | 内容 | IP" data-toggle="tooltip" data-original-title="支持模糊查询（如查询QQ邮箱用户：@qq.com）">
                                        <span class="mdi mdi-magnify"></span>
                                        <div class="input-group-append">
                                            <button v-on:click="initData('','',true)" class="btn btn-primary" type="button">搜索</button>
                                        </div>
                                        <button v-on:click="deleteComments()" type="button" class="btn btn-primary d-none d-lg-block ml-2">
                                            <i class="mdi mdi mdi-delete-outline me-1"></i>批量删除
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 加载动画 开始 -->
                    <div v-show="is_load" class="table-responsive is_load mb-2 flex-center">
                        <div class="spinner-border text-primary m-1" role="status"></div>
                        <div>加载中...</div>
                    </div>
                    <!-- 加载动画 结束 -->
                    
                    <div v-show="!is_load" class="table-responsive-sm">
                        <table class="table custom table-centered mb-0">
                            <thead>
                                <tr>
                                    <th>
                                        <div class="custom-control custom-checkbox">
                                            <input v-on:click="selectAll" type="checkbox" class="custom-control-input" id="select-all">
                                            <label class="custom-control-label" for="select-all"></label>
                                        </div>
                                    </th>
                                    <th class="min-w-175px">昵称</th>
                                    <th class="min-w-175px">来源</th>
                                    <th class="min-w-500px">内容</th>
                                    <th>邮箱</th>
                                    <th>IP</th>
                                    <th class="min-w-200px">浏览器</th>
                                    <th class="min-w-200px">系统</th>
                                    <th class="min-w-125px">时间</th>
                                    <th class="min-w-125px">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr v-for="data in comments.data" :key="data.id">
                                    <td>
                                        <div class="custom-control custom-checkbox">
                                            <input :name="data.id" type="checkbox" class="custom-control-input checkbox-item" :id="'select-' + data.id">
                                            <label class="custom-control-label" :for="'select-' + data.id"></label>
                                        </div>
                                    </td>
                                    <td v-on:click="initData(data.id)" data-toggle="modal" data-target="#fill-edit-modal" class="table-user pointer">
                                        <img :src="data.expand.head_img || ''" class="mr-1 rounded-circle">
                                        {{data.nickname}}
                                    </td>
                                    <td>
                                        {{data.type == 'article' ? '《' + data.expand?.article?.title + '》' : (!empty(data.type) ? data.type : '未知')}}
                                    </td>
                                    <td>{{data.content}}</td>
                                    <td>{{data.email}}</td>
                                    <td>{{data.ip}}</td>
                                    <td>{{data.expand.agent.browser.kernel}} - {{data.expand.agent.browser.version}}</td>
                                    <td>{{data.expand.agent.os.equipment}} - {{data.expand.agent.os.system}} - {{data.expand.agent.os.version}}</td>
                                    <td>{{natureTime(data.create_time)}}</td>
                                    <td>
                                        <button v-on:click="initData(data.id)" data-bs-toggle="modal" data-bs-target="#fill-edit-modal" type="button" class="btn btn-light btn-sm mr-1">
                                            <i class="mdi mdi-square-edit-outline"></i>
                                        </button>
                                        <button v-on:click="deleteComments(data.id)" type="button" class="btn btn-light btn-sm">
                                            <i class="mdi mdi-delete-outline"></i>
                                        </button>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    
                    <div class="flex space-between align-items-center mt-2">
                        <div class="d-none d-md-block">
                            共 {{comments.page}} 页 {{comments.count}} 条数据
                        </div>
                        <div v-if="!page_is_load && is_page_show" class="btn-group">
                            <button v-on:click="initData('',1)" type="button" class="btn btn-light btn-sm"><i class="mdi mdi-chevron-left"></i></button>
                            <button v-for="(item, index) in page_list" :key="index" v-on:click="initData('',item)" :class="(page == item) ? 'btn btn-sm btn-primary' : 'btn btn-sm btn-light'">
                                {{item}}
                            </button>
                            <button v-on:click="initData('',comments.page)" type="button" class="btn btn-light btn-sm"><i class="mdi mdi-chevron-right"></i></button>
                        </div>
                    </div>
                    
                </div>
            </div>
        </div>
    </div>
    
    <!-- 编辑用户 - 结束 -->
    <div id="fill-edit-modal" class="modal fade" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="fill-primary-modalLabel" aria-hidden="true">
        <!-- modal-dialog-centered -->
        <div class="modal-dialog modal-lg">
            <div class="modal-content modal-filled bg-primary">
                <div class="modal-header">
                    <h4 class="modal-title" id="fill-primary-modalLabel">修改评论</h4>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    
                    <div class="row">
                        <div class="col-lg-6">
                            <div class="card-body pb-0">
                                <div class="form-group row mb-3">
                                    <label class="col-3 col-form-label">昵称</label>
                                    <div class="col-9">
                                        <input v-model="edit.nickname" type="text" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group row mb-3">
                                    <label class="col-3 col-form-label">网址</label>
                                    <div class="col-9">
                                        <input v-model="edit.url" type="text" class="form-control">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-6">
                            <div class="card-body pb-0">
                                <div class="form-group row mb-3">
                                    <label class="col-3 col-form-label">邮箱</label>
                                    <div class="col-9">
                                        <input v-model="edit.email" type="text" class="form-control" placeholder="用于登录">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="card-body pt-0">
                            <div class="col-lg-12">
                                <div class="form-group">
                                    <label>评论内容</label>
                                    <textarea class="form-control domain-textarea" rows="5" v-model="edit.content" placeholder="这个人很懒，什么都没写！"></textarea>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-outline-light" data-bs-dismiss="modal">关闭</button>
                    <button v-on:click="save" type="button" class="btn btn-light">保存配置</button>
                </div>
            </div>
        </div>
    </div>
    <!-- 编辑用户 - 结束 -->
</div>
{/block}

{block name="script"}
<script src="{$CONFIG->ROOT}js/pages/manage-comments.js?v={$CONFIG->VERSION}"></script>
{/block}